/*     */ package com.zimbra.cs.account.ldap.upgrade;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.ldap.LdapDIT;
/*     */ import com.zimbra.cs.account.ldap.LdapProv;
/*     */ import com.zimbra.cs.ldap.IAttributes;
/*     */ import com.zimbra.cs.ldap.LdapClient;
/*     */ import com.zimbra.cs.ldap.LdapServerType;
/*     */ import com.zimbra.cs.ldap.LdapUsage;
/*     */ import com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor;
/*     */ import com.zimbra.cs.ldap.ZLdapContext;
/*     */ import com.zimbra.cs.ldap.ZLdapFilter;
/*     */ import com.zimbra.cs.ldap.ZLdapFilterFactory;
/*     */ import com.zimbra.cs.ldap.ZMutableEntry;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class BUG_53745
/*     */   extends UpgradeOp
/*     */ {
/*  32 */   private static String ATTR_IMPORTEXPORT = "zimbraFeatureImportExportFolderEnabled";
/*  33 */   private static String ATTR_IMPORT = "zimbraFeatureImportFolderEnabled";
/*  34 */   private static String ATTR_EXPORT = "zimbraFeatureExportFolderEnabled";
/*     */   
/*     */   void doUpgrade() throws ServiceException
/*     */   {
/*  38 */     ZLdapContext zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.UPGRADE);
/*     */     try {
/*  40 */       doCos(zlc);
/*  41 */       doAccount(zlc);
/*     */     } finally {
/*  43 */       LdapClient.closeContext(zlc);
/*     */     }
/*     */   }
/*     */   
/*     */   private static class Bug53745Visitor extends SearchLdapOptions.SearchLdapVisitor
/*     */   {
/*     */     private UpgradeOp upgradeOp;
/*     */     private ZLdapContext modZlc;
/*     */     
/*     */     Bug53745Visitor(UpgradeOp upgradeOp, ZLdapContext modZlc) {
/*  53 */       super();
/*  54 */       this.upgradeOp = upgradeOp;
/*  55 */       this.modZlc = modZlc;
/*     */     }
/*     */     
/*     */     public void visit(String dn, IAttributes ldapAttrs)
/*     */     {
/*  60 */       ZMutableEntry entry = LdapClient.createMutableEntry();
/*     */       try
/*     */       {
/*  63 */         String importExportVal = ldapAttrs.getAttrString(BUG_53745.ATTR_IMPORTEXPORT);
/*  64 */         String importVal = ldapAttrs.getAttrString(BUG_53745.ATTR_IMPORT);
/*  65 */         String exportVal = ldapAttrs.getAttrString(BUG_53745.ATTR_EXPORT);
/*     */         
/*  67 */         if (importExportVal != null) {
/*  68 */           if (importVal == null) {
/*  69 */             entry.setAttr(BUG_53745.ATTR_IMPORT, importExportVal);
/*     */           }
/*     */           
/*  72 */           if (exportVal == null) {
/*  73 */             entry.setAttr(BUG_53745.ATTR_EXPORT, importExportVal);
/*     */           }
/*     */         }
/*     */         
/*  77 */         this.upgradeOp.replaceAttrs(this.modZlc, dn, entry);
/*     */       }
/*     */       catch (ServiceException e)
/*     */       {
/*  81 */         this.upgradeOp.printer.println("Caught ServiceException while modifying " + dn);
/*  82 */         this.upgradeOp.printer.printStackTrace(e);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   private void upgrade(ZLdapContext modZlc, String[] bases, String query) {
/*  88 */     SearchLdapOptions.SearchLdapVisitor visitor = new Bug53745Visitor(this, modZlc);
/*     */     
/*  90 */     String[] attrs = { ATTR_IMPORTEXPORT, ATTR_IMPORT, ATTR_EXPORT };
/*     */     
/*  92 */     for (String base : bases) {
/*     */       try {
/*  94 */         this.prov.searchLdapOnMaster(base, query, attrs, visitor);
/*     */       }
/*     */       catch (ServiceException e) {
/*  97 */         this.printer.println("Caught ServiceException while searching " + query + " under base " + base);
/*  98 */         this.printer.printStackTrace(e);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   private String query() {
/* 104 */     return "(" + ATTR_IMPORTEXPORT + "=*)";
/*     */   }
/*     */   
/*     */   private void doCos(ZLdapContext modZlc) {
/* 108 */     String[] bases = this.prov.getDIT().getSearchBases(32);
/* 109 */     String query = "(&" + ZLdapFilterFactory.getInstance().allCoses().toFilterString() + query() + ")";
/* 110 */     upgrade(modZlc, bases, query);
/*     */   }
/*     */   
/*     */   private void doAccount(ZLdapContext modZlc) {
/* 114 */     String[] bases = this.prov.getDIT().getSearchBases(1);
/* 115 */     String query = "(&" + ZLdapFilterFactory.getInstance().allAccounts().toFilterString() + query() + ")";
/* 116 */     upgrade(modZlc, bases, query);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/ldap/upgrade/BUG_53745.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */